package com.ruoyi.house.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.filter.ID;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.house.domain.AtbHouseDetail;
import com.ruoyi.house.domain.Plot;
import com.ruoyi.house.mapper.AtbHouseDetailMapper;
import com.ruoyi.house.service.AtbHouseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.house.mapper.AtbHouseMapper;
import com.ruoyi.house.domain.AtbHouse;
import com.ruoyi.house.service.IAtbHouseService;

/**
 * 房屋基础Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@Service
public class AtbHouseServiceImpl implements IAtbHouseService 
{
    @Autowired
    private AtbHouseMapper atbHouseMapper;

    @Autowired
    AtbHouseDetailService houseDetailService;

    /**
     * 查询房屋基础
     * 
     * @param id 房屋基础主键
     * @return 房屋基础
     */
    @Override
    public AtbHouse selectAtbHouseById(Long id)
    {
        return atbHouseMapper.selectAtbHouseById(id);
    }

    /**
     * 查询房屋基础列表
     * 
     * @param atbHouse 房屋基础
     * @return 房屋基础
     */
    @Override
    public List<AtbHouse> selectAtbHouseList(AtbHouse atbHouse)
    {
        return atbHouseMapper.selectAtbHouseList(atbHouse);
    }

    /**
     * 新增房屋基础
     * 
     * @param atbHouse 房屋基础
     * @return 结果
     */
    @Override
    public int insertAtbHouse(AtbHouse atbHouse)
    {
        ID id = new ID();
        atbHouse.setId(id.getId());
        atbHouse.setCreateTime(DateUtils.getNowDate());
        AtbHouseDetail atbHouseDetail = BeanUtil.toBean(atbHouse, AtbHouseDetail.class);
        houseDetailService.insertDetail(atbHouseDetail);
        return atbHouseMapper.insertAtbHouse(atbHouse);
    }

    /**
     * 修改房屋基础
     * 
     * @param atbHouse 房屋基础
     * @return 结果
     */
    @Override
    public int updateAtbHouse(AtbHouse atbHouse)
    {
        return atbHouseMapper.updateAtbHouse(atbHouse);
    }

    /**
     * 批量删除房屋基础
     * 
     * @param ids 需要删除的房屋基础主键
     * @return 结果
     */
    @Override
    public int deleteAtbHouseByIds(Long[] ids)
    {
        for (Long id : ids) {
            houseDetailService.removeById(id);
        }
        return atbHouseMapper.deleteAtbHouseByIds(ids);
    }

    /**
     * 删除房屋基础信息
     * 
     * @param id 房屋基础主键
     * @return 结果
     */
    @Override
    public int deleteAtbHouseById(Long id)
    {
        return atbHouseMapper.deleteAtbHouseById(id);
    }

    @Override
    public List<Plot> selectPlot() {
        return atbHouseMapper.selectPlot();
    }
}
